import { createRouter, createWebHistory } from 'vue-router'
import LayOut from "@/views/View/LayOut.vue";
import ResumeUpload from "@/views/View/ResumeManage/ResumeUpload.vue";
import PostUpLoad from "@/views/View/PostManage/PostUpLoad.vue";
import Login from "@/views/View/Login.vue";
import Parse from "@/views/View/Parse.vue";
import Resign from "@/views/View/Resign.vue";
import Analysis from "@/views/View/Analysis.vue";
import jilu from '@/views/View/jilu.vue'
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',redirect:"/login",
      name: 'LayOut',
      component: LayOut,
      children:[
          { path: '/resumeUpload', name:'resumeUpload',component: ResumeUpload },
          { path:'/postUpload',name :'postUpLoad',component:PostUpLoad},
          { path:'/parse',name :'Parse',component:Parse},
          {path:'/analysis',name :'analysis',component:Analysis},
          {path:'/jilu',name :'jilu',component:jilu}
      ]
    },
    {
      path: '/login',
      name:'Login',
      component:Login
    },
    {
      path: '/resign',
      name:'Resign',
      component:Resign
    }


  ]
})
router.beforeEach((to,from,next)=>{
  if(to.path=='/login'&&from.path=='/'){
    console.log("hello");
    console.log(to);
    localStorage.removeItem("username");
    // console.log();
    // 用户名初始清空
}
let user = localStorage.getItem("username");
// 获取user字段，没有登录为空
console.log(user);
console.log(to);
if(!user&&to.path=='/resign'){
  // next({path:'/resign'})
  console.log('helloword');
  next()
  if(to.path!='/login'){
    next(false);
  }
}else if(!user&&to.path!='/login'){
  console.log("resign");
  next({path:'/login'})
}
else{
  next();
}
}
)

export default router
